package com.cskaoyan.mall.product.controller;

import com.cskaoyan.mall.common.result.Result;
import com.cskaoyan.mall.product.converter.param.PlatformAttributeInfoParamConverter;
import com.cskaoyan.mall.product.dto.PlatformAttributeInfoDTO;
import com.cskaoyan.mall.product.dto.PlatformAttributeValueDTO;
import com.cskaoyan.mall.product.mapper.PlatformAttrInfoMapper;
import com.cskaoyan.mall.product.mapper.PlatformAttrValueMapper;
import com.cskaoyan.mall.product.model.PlatformAttributeInfo;
import com.cskaoyan.mall.product.query.PlatformAttributeParam;
import com.cskaoyan.mall.product.query.PlatformAttributeValueParam;
import com.cskaoyan.mall.product.service.PlatformAttributeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author Pudding
 * @Date 2024/6/29 15:50
 * 后台管理：平台属性
 */
@RestController
public class AdminPlatformController {

    @Autowired
    PlatformAttributeService platformAttributeService;

    //1. 根据分类Id查询平台属性以及平台属性值
    //http://localhost/admin/product/attrInfoList/3/20/149
    @GetMapping("/admin/product/attrInfoList/{firstLevelCategoryId}/{secondLevelCategoryId}/{thirdLevelCategoryId}")
    public Result getAttrInfoList(@PathVariable Long firstLevelCategoryId, @PathVariable Long secondLevelCategoryId, @PathVariable Long thirdLevelCategoryId) {

        List<PlatformAttributeInfoDTO> platformAttrInfoList = platformAttributeService.getPlatformAttrInfoList(firstLevelCategoryId, secondLevelCategoryId, thirdLevelCategoryId);
        return Result.ok(platformAttrInfoList);
    }

    //2. 保存平台属性   修改平台属性
    //http://localhost/admin/product/saveAttrInfo
    @PostMapping("/admin/product/saveAttrInfo")
    public Result saveAttrInfo(@RequestBody PlatformAttributeParam platformAttributeParam) {

        platformAttributeService.savePlatformAttrInfo(platformAttributeParam);
        return Result.ok();
    }

    //3. 平台属性值回显，点击修改按钮时，进行查询平台属性值
    //http://localhost/admin/product/getAttrValueList/106
    @GetMapping("/admin/product/getAttrValueList/{attrId}")
    public Result<List<PlatformAttributeValueDTO>> getAttrValueList(@PathVariable Long attrId) {

        List<PlatformAttributeValueDTO> platformAttrInfo = platformAttributeService.getPlatformAttrValueList(attrId);
        return Result.ok(platformAttrInfo);
    }
}
